define(function() {
	return function($compile, $scope) {
		require(
				[ "AppPathDir/register/personInfos/personSupport",
						"AppPathDir/register/personInfos/addSupport",
						"AppPathDir/register/personInfos/updateSupport",
						"PDUtilDir/util", "PDUtilDir/tool",
						"PDUtilDir/slidebar", "PDUtilDir/inputSelect","Date",
						"DateCN", "css!DateCss" ],
				function(Support, AddSupport, UpdateSupport, Util, Tool,
						Slidebar, inputSelect) {
					/* 查询 start */
					$scope.cache = {
						types : new Array(),
						roles : new Array(),
						works:new Array(),
						projects : new Array(),
						workerType : new Array(),
						typeMap: new Map(),
						workerTypeMap:new Map(),
						rolesMap:new Map(),
						projectsMap:new Map(),
						teamsMap:new Map(),
						worksMap:new Map(),
						certificates : new Array()
					};
					$scope.entity = {
							projectCode : '',
							projectCodes:'',
							
							
						};
			
					$scope.search = {
							name : "",
							personNo : "",
							projectCode : "",
							sex:"",
							startTime:"",
							endTime:""
					}
					$scope.searchSupport = {
							
						run : function() {
							$scope.grid.reload({
								queryParam : {
									name : $scope.search.name,
									personNo : $scope.search.personNo,
									projectCode : $scope.search.projectCode,
									sex: $scope.search.sex,
									startTime: $scope.search.startTime,
									endTime: $scope.search.endTime,
								}
							})
						}
					
					};
					/* 查询 end */
//					$scope.addSupport = AddSupport($scope, $compile);
					$scope.updateSupport = UpdateSupport($scope, $compile);

					$scope.delSupport = {
						run : function() {
					
							var selectRows = $scope.grid.getSelectedRow();
							if (null != selectRows && selectRows.length>0) {
								Util.confirm("是否要删除", function() {
									var ids = new Array();
									$.each(selectRows, function(index, selectRow) {
										ids.push(selectRow.id);
									});
									$.ajax({
										url : getServer()
												+ "/flea/hclv/person/deleteByIds.htmls",
										method : 'post',
										data : {
											'ids' : JSON.stringify(ids)
										},
										success : function(data) {
											$scope.grid.refresh();
											Util.alert(data.message);
										}
									});

								});
							} else {
								Util.alert('请选择要删除的数据！');
							}
						}
					};
					$scope.gridRender = function() {
						if($scope.cache.projects.length > 0){
							$scope.grid = Support.init($scope.cache, $scope.addSupport,
									$scope.updateSupport, $scope.delSupport,
									$scope.searchSupport);
						}
					};
					
					var init = function() {
						//游客类型
						$.ajax({
							url : getServer() + "/flea/hclv/getDictWorkType.htmls",
							success : function(data) {
								$scope.cache.workerType = data.data;
								$.each(data.data, function(index, row) {
									$scope.cache.workerTypeMap.set(row.dictCode, row.dictName);
								});
//								$scope.gridRender();
							}
						});
						$.ajax({
							url : getServer() + "/flea/hclv/getTeams.htmls",
							success : function(data) {
								$scope.cache.teams = data.data;
								$.each(data.data, function(index, row) {
									$scope.cache.teamsMap.set(row.dictCode, row.dictName);
								});
//								$scope.gridRender();
							}
						});
						$.ajax({
							url : getServer() + "/flea/hclv/getWork.htmls",
							success : function(data) {
								$scope.cache.works = data.data;
								$.each(data.data, function(index, row) {
									$scope.cache.worksMap.set(row.dictCode, row.dictName);
								});
//								$scope.gridRender();
							}
						});
						//游客类型
						$.ajax({
							url : getServer() + "/flea/hclv/getFaceRoleType.htmls",
							success : function(data) {
								$scope.cache.roles = data.data;
								$.each(data.data, function(index, row) {
									$scope.cache.rolesMap.set(row.dictCode, row.dictName);
								});
//								$scope.gridRender();
							}
						});
						//游客类型
						$.ajax({
							url : getServer() + "/flea/hclv/getDictHTProject.htmls",
							success : function(data) {
								$scope.cache.projects = data.data;
								$.each(data.data, function(index, row) {
									$scope.cache.projectsMap.set(row.dictCode, row.dictName);
								});
								$scope.gridRender();
								
								inputSelect.dropCache();
								inputSelect({
									id : "projectName",
									key : {
										id : "dictCode",
										name : "dictName",
										data : "data",
									},
									data : $scope.cache.projects,
									simpleData : true,
									// 启用文本搜索
									// initData:[initProvice],
									searchAble : false,
									callback : function(id) {
										$scope.search.projectCode = id[0];
										$scope.search.projectName = id[1];
									}
								});
								var sext=[{'dictCode':'男','dictName':'男'},{'dictCode':'女','dictName':'女'}];
								inputSelect.dropCache();
								inputSelect({
									id : "sexName",
									key : {
										id : "dictCode",
										name : "dictName",
										data : "data",
									},
									data : sext,
									simpleData : true,
									// 启用文本搜索
									// initData:[initProvice],
									searchAble : false,
									callback : function(id) {
										$scope.search.sex = id[0];
										$scope.search.sexName = id[1];
									}
								});
								
								
								
							}
						});
//						 $("#queryStart").datetimepicker({
//					            //设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
//					            language : "cn",
//					            //输出格式化
//					            format : 'yyyy-mm-dd',
//					            //直接选择‘今天’
//					            todayBtn : true,
//					            //设置最精确的时间选择视图
//					            minView : 'month',
//					            //高亮当天日期
//					            todayHighlight : true,
//					            //选择完毕后自动关闭
//					            autoclose : true
//					        });
						setTimeout($scope.gridRender(),3000 ); 
					
					}
					init();
				})
	}
});